﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
using Csla.Data;

namespace Kiosk.Library
{
    public partial class NotificationTypeInfo
    {
        public static NotificationTypeInfo GetNotificationTypeInfoByName(string name)
        {
            return DataPortal.Fetch<NotificationTypeInfo>(new SingleCriteria<NotificationTypeInfo, string>(name));
        }

        private void DataPortal_Fetch(SingleCriteria<NotificationTypeInfo, string> criteria)
        {
            FetchByName(criteria.Value);
        }

        private void FetchByName(string name)
        {
            using (var ctx = ContextManager<Kiosk.Data.KioskDataContext>.GetManager(Database.ConnectionString))
            {
                var data = ctx.DataContext.NotificationType.Single(t => t.Name == name);
                this.NotificationTypeID = data.NotificationTypeID;
                this.Name = data.Name;
            }
        }

    }
}
